package com.iss.umservice.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.iss.umservice.bean.TutorBean;
import com.iss.umservice.dao.TutorDao;

@Repository
public class TutorDaoImpl extends SqlMapClientDaoSupport implements TutorDao
{
    @SuppressWarnings("unchecked")
    @Override 
    public void addTutor(TutorBean tutor)
    {
        tutor.setId("tutorid");
        getSqlMapClientTemplate().insert("tutor.addTutor", tutor);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public int countTutor()
    {
        int count = ((Integer)getSqlMapClientTemplate().queryForObject("tutor.countTutor")).intValue();
        return count;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public List<TutorBean> queryTutor(int offset, int row)
    {
        return getSqlMapClientTemplate().queryForList("tutor.queryTutor", offset, row);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public List<TutorBean> queryTutorFront()
    {
        return getSqlMapClientTemplate().queryForList("tutor.queryTutor");
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public TutorBean queryTutorById(String id)
    {
        Map<String,Object> args = new HashMap<String,Object>();
        args.put("id", id);
        return (TutorBean)getSqlMapClientTemplate().queryForObject("tutor.queryTutorById", args);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public void modifyTutor(TutorBean tutor)
    {
        getSqlMapClientTemplate().update("tutor.modifyTutor", tutor);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public void deleteTutor(TutorBean tutor)
    {
        getSqlMapClientTemplate().update("tutor.deleteTutor", tutor);
    }
}
